package com.spsy.order.controller;
import com.alibaba.fastjson2.JSON;
import com.spsy.api.pay.PayApi;
import com.bw.spsy.vo.AddOrderVo;
import com.spsy.common.core.domain.R;
import com.spsy.order.domain.Order;
import com.spsy.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author: liuzhiping
 * @date: 2025/9/19 17:05
 **/
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderOptsController {

    @Autowired
    private PayApi payApi;

    @Autowired
    private IOrderService iOrderService;


    //rabbitmq  【削】峰  10w/s
    //用户需要【3.03秒】  10w用户，100个机子（10个线程）= 【5.6分钟】350秒
    @PostMapping(value = "/create",consumes = MediaType.APPLICATION_JSON_VALUE)
    public R createOrder(@RequestBody AddOrderVo addOrderVo) throws Exception{

        log.info("订单系统-参数：addOrderVo：{}", JSON.toJSONString(addOrderVo));


        log.info("订单系统-参数255555：addOrderVo2555：{}", JSON.toJSONString(addOrderVo));

        //入数据库的
        int count = iOrderService.insertOrder(Order.builder().orderNo(UUID.randomUUID().toString()).orderStatus(1).build());


        log.info("订单系统-参数2：count：{}", JSON.toJSONString(count));
        R r = payApi.createOrder(addOrderVo);


        // TODO 发一个短信给用户，你下单成功了，赶紧支付，要不活动结束 3S。
        //{发送短信消息给用户}

        log.info("r:{}",JSON.toJSONString(r));


        return r;

    }
}
